import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class LoadingDialog extends Dialog {

  final double _dialogSize = 180.w;

  final String text;

  final DateTime _showTime = DateTime.now();

  LoadingDialog(this.text, {Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        if (DateTime.now().difference(_showTime).inSeconds >= 5) {
          Navigator.pop(context);
        }
      },
      child: Center(
        child: Material(
          type: MaterialType.transparency,
          child: Container(
            width: _dialogSize,
            height: _dialogSize,
            alignment: Alignment.center,
            decoration: BoxDecoration(
                color: Color.fromRGBO(0, 0, 0, 0.5),
                borderRadius:
                BorderRadius.all(Radius.circular(10.w))),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Theme(
                  data: ThemeData(
                    cupertinoOverrideTheme: CupertinoThemeData(
                      brightness: Brightness.dark,
                    ),
                  ),
                  child: CupertinoActivityIndicator(
                    radius: 30.w,
                  ),
                ),
                SizedBox(height: 14.w),
                Text(
                  text,
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 24.sp,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}